package com.d2rv.vrpn;

import vrpn.ButtonRemote;

/**
 * Button listener for VRPNClient
 *
 * @author Darrieutort A., Dupouy A., Rossignol L., Van Poucke A.
 */
public class VRPNButtonListener implements ButtonRemote.ButtonChangeListener {

    /**
     * Represents the states of the buttons to listen (on = 1, off = 0)
     */
    private boolean[] states;

    /**
     * Shared array of the states of the buttons with VRPNClient
     * @param states
     */
    public VRPNButtonListener(boolean[] states) {
        this.states = states;
    }

    /**
     * Changes the state of the button u
     * @param u id button to update
     * @param button
     */
    public void buttonUpdate(ButtonRemote.ButtonUpdate u, ButtonRemote button) {
        this.states[u.button] = (u.state == 1) ? true : false;
    }
}